package com.zdsoft.blp.zongbuju.wode.activity;

import android.app.Service;
import android.content.Intent;
import android.media.RingtoneManager;
import android.os.Vibrator;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.zdsoft.blp.R;
import com.zdsoft.blp.gongyong.fanhui.FanHuiView;
import com.zdsoft.blp.gongyong.net.BaseActivity;

/**
 * Created by Administrator on 2016/9/1.
 */
public class SheZhiActivity extends BaseActivity implements View.OnClickListener{

    private FanHuiView back;
    private ImageView iv_xxtz,iv_sy,iv_zd;
    private boolean offOrOn;
    private LinearLayout ll_xxhide,ll_tzls;
    private RelativeLayout rl_lings;
    private Vibrator vibrator=null;
    @Override
    protected void init() {
        setContentView(R.layout.shezhi_wode);
        back = find(R.id.back);
        back.getTv_title().setText("设置");
        offOrOn =true;
        iv_xxtz = find(R.id.iv_xxtz);
        iv_sy = find(R.id.iv_sy);
        iv_zd = find(R.id.iv_zd);
        ll_xxhide = find(R.id.ll_xxhide);
        ll_tzls = find(R.id.ll_tzls);
        rl_lings = find(R.id.rl_lings);


        iv_xxtz.setOnClickListener(this);
        iv_sy.setOnClickListener(this);
        iv_zd.setOnClickListener(this);
        rl_lings.setOnClickListener(this);
        vibrator=(Vibrator)getSystemService(Service.VIBRATOR_SERVICE);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iv_xxtz:
                setIamge(iv_xxtz);
                if(!offOrOn){
                    ll_xxhide.setVisibility(View.GONE);
                }else {
                    ll_xxhide.setVisibility(View.VISIBLE);
                }
                break;
            case R.id.iv_sy:
                setIamge(iv_sy);
                if(!offOrOn){
                    ll_tzls.setVisibility(View.GONE);
                }else {
                    ll_tzls.setVisibility(View.VISIBLE);
                }
                break;
            case R.id.iv_zd:
                setIamge(iv_zd);
                if(offOrOn){
                    vibrator.vibrate(200);
                }else {
                    if(vibrator.hasVibrator()){
                        vibrator.cancel();
                    }
                }
                break;
            case R.id.rl_lings:
                Intent intent  = new Intent(getApplicationContext(),XZeLingSActivity.class);
                startActivity(intent);
                break;
        }
    }


    public void setIamge(ImageView iamge) {
        if(offOrOn){
            iamge.setImageResource(R.drawable.off350);
            offOrOn =false;
        }else {
            iamge.setImageResource(R.drawable.on350);
            offOrOn = true;
        }

    }
}
